export default {
  data() {
    return {
      tableData: [],
    }
  },
  //进入页面加载
  mounted: function () {
    var that = this;
    //在缓存中获取值
    that.user_name = sessionStorage.getItem("user_name");
    that.user_id = sessionStorage.getItem("user_id");
    that.token = sessionStorage.getItem("access-token");
    if ((!that.token) || (!that.user_id) || (!that.user_name)) {
      that.$router.push('/login');
    }
    that.getList();
  },

  //方法
  methods: {
    //请求api
    getList() {
      var that = this;
      that.tableData = [];
      //请求的数据
      var formData = {};
      formData.token = that.token;
      formData.type = that.type;

      //请求邀请者列表
      that.$http.post(that.adminApi.api_url + "/api/Bannerimg/index", formData, {
        emulateJSON: true
      }).then(
        function (res) {
          // 处理成功的结果
          if (res.body) {
            for (var i in res.body.list) {
              if (res.body.list[i].status === 1) {
                var status_text = '展示';
              } else {
                var status_text = '不展示';
              }
              that.tableData.push({
                i: i,
                id: res.body.list[i].id,
                img: "<img src =" + res.body.list[i].picture + " style='height:100px'/ >",
                sort: res.body.list[i].sort,
                url: res.body.list[i].url,
                create_time: res.body.list[i].create_time,
                status: status_text,
                illustrate: "<span>" + res.body.list[i].system_manager_id + "<span><br /><span>" + res.body.list[i].system_manager_time + "<span>"
              });
            }
          }
        },
        function () {
          // 处理失败的结果
          that.$message({
            type: 'error',
            message: `操作提示: ${ '处理异常' }`
          });
        });
    },

    //添加城市轮播
    add: function () {
      var that = this;
      that.$router.push({
        path: '/swiper/add_swiper'
      });
    },

    //修改轮播
    edit: function (id) {
      var that = this;
      that.$router.push({
        path: '/swiper/add_swiper',
        query: {
          swiper_id: id
        }
      });
    },

    //删除轮播
    deleteRow: function (e) {
      var that = this;
      that.$confirm('此操作将永久删除该图片, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        that.doDelete(e);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //执行删除
    doDelete: function (e) {
      var that = this;
      //请求登陆接口
      that.$http.post(that.adminApi.api_url + "/api/Bannerimg/del", {
        token: that.token,
        id: e
      }, {
        emulateJSON: true
      }).then(
        function (res) {
          // 处理成功的结果
          that.$message({
            type: 'success',
            message: `操作提示: ${ '删除成功' }`
          });
          that.getList();
        },
        function () {
          // 处理失败的结果
          that.$message({
            type: 'error',
            message: `操作提示: ${ '处理异常' }`
          });
        });
    },
  }
}
